package com.gyx.lottery.dao.mapper;

import com.gyx.lottery.dao.dataobject.ActivityUserDO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ActivityUserMapper {
    @Insert("<script> " +
            " insert into activity_user " +
            " (activity_id,user_id,user_name,status) " +
            " values " +
            " <foreach item='item' collection='items' index='index' separator=',' > " +
            " (#{item.activityId},#{item.userId},#{item.userName},#{item.status})" +
            " </foreach>" +
            " </script>")
    @Options(useGeneratedKeys = true ,keyProperty = "id",keyColumn = "id")
    void batchInsert(@Param("items") List<ActivityUserDO> activityUserDOList);
@Select("select * from activity_user where activity_id=#{activityId}")
    List<ActivityUserDO> selectById(@Param("activityId") Long activityId);
@Update("<script> " +
        " update activity_user set status=#{status} " +
        " where activity_id=#{activityId} " +
        " and user_id in " +
        " <foreach collection='ids' item='id' close=')' open='(' separator=','>" +
        " #{id}"+
        " </foreach>" +
        " </script>")

    void updateStatusByIds(@Param("activityId") Long activityId,
                           @Param("ids") List<Long> ids,
                           @Param("status") String status);
    @Select("<script> " +
            " select * from activity_user where activity_id=#{activityId} " +
            " and user_id in " +
            " <foreach collection='ids' item='id' open='(' close=')' separator=','> " +
            " #{id} " +
            " </foreach>" +
            " </script>")
    List<ActivityUserDO> selectByIdAndUserId(@Param("activityId") Long activityId,@Param("ids")  List<Long> ids);
}
